Skip to content

Add migration to merge dittos in stats#348

Merged
Fabio1988 merged 3 commits intomainfrom
fix-ditto-stats
Mar 24, 2026
Merged

Add migration to merge dittos in stats#348
Fabio1988 merged 3 commits intomainfrom
fix-ditto-stats

Conversation

@Fabio1988
Copy link
Copy Markdown
Collaborator

@Fabio1988 Fabio1988 commented Mar 22, 2026

closes #347

@Fabio1988 Fabio1988 changed the title Add SQL script to merge and update pokemon_stats Add SQL script to merge dittos in stats Mar 22, 2026
@Fabio1988 Fabio1988 changed the title Add SQL script to merge dittos in stats Add migration to merge dittos in stats Mar 22, 2026
@lenisko
Copy link
Copy Markdown
Contributor

lenisko commented Mar 22, 2026

Hmmm...

  1. Those tables are missing in migration:
pokemon_hundo_stats
pokemon_iv_stats
pokemon_nundo_stats
pokemon_shiny_stats
  1. I wouldn't create temporary table, maybe just set them temporary as pokemon_id = 65535, remove and them update? Or make a new table with more randomized name :)

@jfberry
Copy link
Copy Markdown
Collaborator

jfberry commented Mar 22, 2026

The rows need merging not updating; I’m not sure it can easily be done without a temp table. Can you expand on your suggestion Len?

@lenisko
Copy link
Copy Markdown
Contributor

lenisko commented Mar 22, 2026

@jfberry something like that

START TRANSACTION;

UPDATE pokemon_stats SET pokemon_id = 65535 WHERE pokemon_id = 132;

INSERT INTO pokemon_stats (date, area, fence, pokemon_id, form_id, count)
SELECT
    date,
    area,
    fence,
    132 AS pokemon_id,
    0   AS form_id,
    SUM(count) AS count
FROM pokemon_stats
WHERE pokemon_id = 65535
GROUP BY date, area, fence
ON DUPLICATE KEY UPDATE
    count = count + VALUES(count);

DELETE FROM pokemon_stats WHERE pokemon_id = 65535;

COMMIT;

But yeah, just noticed its temporary table creation so it doesn't really matter. Either way we need to run it for multiple tables not single.

@jfberry
Copy link
Copy Markdown
Collaborator

jfberry commented Mar 22, 2026

Actually this approach might work even without moving the pokemon id since you can do form<>0

worth a go.

@Fabio1988 Fabio1988 merged commit 34e4a68 into main Mar 24, 2026
4 checks passed
@Fabio1988 Fabio1988 deleted the fix-ditto-stats branch March 24, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pokemon stats - unify table after Ditto changes

3 participants